package com.example.ykbboom.universitytransportation.View;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.ykbboom.universitytransportation.MyApplication;
import com.example.ykbboom.universitytransportation.POJO.RequestDetailItem;
import com.example.ykbboom.universitytransportation.R;

import java.util.List;

/**
 * Created by ykbboom on 2017/3/14 15:09
 * email：ykbpro@whut.edu.cn
 */

public class RequestDetailAdapter extends RecyclerView.Adapter<RequestDetailAdapter.ViewHolder> {

    private List<RequestDetailItem>list;
    private Context context = MyApplication.getContext();
    public RequestDetailAdapter(List<RequestDetailItem>list){
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.request_detail_item_layout,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        RequestDetailItem requestDetailItem = list.get(position);
        Glide.with(context).load(requestDetailItem.getImgId()).into(holder.img);
        holder.textView.setText(requestDetailItem.getInfo() );
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView img;
        TextView textView;
        public ViewHolder(View view){
            super(view);
            img = (ImageView) view.findViewById(R.id.request_detail_item_imgview);
            textView = (TextView) view.findViewById(R.id.request_detail_item_text);
        }
    }
}
